/*
 *  AudioChannelStreamer.h
 *  SoundController0002
 *
 *  Created by jiro on 10/07/03.
 *  Copyright 2010 jiro music. All rights reserved.
 *
 */

#pragma once

#include "AudioChannel.h"
#include "AudioTrackStream.h"

namespace sc
{
	template< class AudioData >
	class AudioChannelStream
	{
	protected:

		std::vector< AudioTrackStream< AudioData > > audioTrackStreams;

	public:
	
		AudioChannelStream()
		{}
		
		AudioChannelStream( const AudioChannel< AudioData >& audioChannel )
			: AudioChannel< AudioData >::audioTracks( audioChannel.audioTracks )
		{
			size_t count = audioChannel.audioTracks.size();
			audioTrackStreams.resize( count );
			for ( size_t i = 0; i < count; i++ )
			{
				audioTrackStreams[ i ] = audioChannel.audioTracks[ i ];
			}
		}

		void StartStreaming( double time )
		{
			size_t count = audioTrackStreams.size();
			for ( size_t i = 0; i < count; i++ )
			{
				audioTrackStreams[ i ].StartStreaming( time );
			}
		}
		
		float Stream()
		{
			AudioData audioData = 0.0f;
			size_t count = audioTrackStreams.size();
			for ( size_t i = 0; i < count; i++ )
			{
				audioData += audioTrackStreams[ i ].Stream();
			}
			return audioData;
		}

		bool IsStreamingEnd() const
		{
			size_t count = audioTrackStreams.size();
			for ( size_t i = 0; i < count; i++ )
			{
				if ( ! audioTrackStreams[ i ].IsStreamingEnd() )
				{
					return false;
				}
			}
			return true;
		}
	};
}